import { queryChargeList } from '../services/api';

export default {
  namespace: 'charge',

  state: {
    data: {list: [], pagination: {size: 10, current: 1, total: 0}},
    loading: false,
  },

  effects: {
    *fetch({ payload }, { call, put }) {
      yield put({
        type: 'changeLoading',
        payload: true,
      });
      const response = yield call(queryChargeList, payload);
      yield put({
        type: 'save',
        payload: {pagination:response.page,list:response.data},
      });
      yield put({
        type: 'changeLoading',
        payload: false,
      });
    },
  },

  reducers: {
    save(state, action) {
      return {
        ...state,
        data: action.payload,
      };
    },
    changeLoading(state, action) {
      return {
        ...state,
        loading: action.payload,
      };
    },
  },
};
